#include "stdafx.h"

Renderer::Renderer()
{

}

void Renderer::PushLine(int x1, int y1)
{
    // Inverse Y because GLUT is fucking retarded
    y1 = glutGet(GLUT_WINDOW_HEIGHT) - y1;\

    float fx1 = pixelToFloat(x1, GLUT_WINDOW_WIDTH);
    float fy1 = pixelToFloat(y1, GLUT_WINDOW_HEIGHT);

    //draw a line
    //glColor3fv(BLACK);
    //glLineWidth(5.0f);
	//glBegin(GL_LINE_STRIP);
        glVertex2f(fx1, fy1);
        //glVertex2f(fx2, fy2);
    //glEnd();
}

void Renderer::RenderQuad(int x, int y, int w, int h, GLfloat *COLOR)
{
    // Inverse Y because GLUT is fucking retarded
    y = glutGet(GLUT_WINDOW_HEIGHT) - y;

    float x1 = pixelToFloat(x, GLUT_WINDOW_WIDTH);
    float y1 = pixelToFloat(y, GLUT_WINDOW_HEIGHT);

    float x2 = pixelToFloat(x + w, GLUT_WINDOW_WIDTH);
    float y2 = pixelToFloat(y, GLUT_WINDOW_HEIGHT);

    float x3 = pixelToFloat(x + w, GLUT_WINDOW_WIDTH);
    float y3 = pixelToFloat(y - h, GLUT_WINDOW_HEIGHT);

    float x4 = pixelToFloat(x, GLUT_WINDOW_WIDTH);
    float y4 = pixelToFloat(y - h, GLUT_WINDOW_HEIGHT);

    glColor3fv(COLOR);
    glBegin(GL_POLYGON);
        glVertex2f(x1, y1);
        glVertex2f(x2, y2);
        glVertex2f(x3, y3);
        glVertex2f(x4, y4);
    glEnd();
}

void Renderer::PrintText(int x, int y, LPVOID font, GLfloat *COLOR, std::string text)
{ 
    // Inverse Y because GLUT is fucking retarded
    y = glutGet(GLUT_WINDOW_HEIGHT) - y;

    float x1 = pixelToFloat(x, GLUT_WINDOW_WIDTH); //((x / (float)glutGet()) * 2.0f) - 1.0f;
    float y1 = pixelToFloat(y, GLUT_WINDOW_HEIGHT); //((y / (float)glutGet(GLUT_WINDOW_HEIGHT)) * 2.0f) - 1.0f;

    glColor3fv(COLOR);
    for (unsigned int i = 0; i < text.size(); i++)
    {
        glRasterPos3f(x1 + ((i*17)/ (float)glutGet(GLUT_WINDOW_WIDTH)), y1, 0);
        glutBitmapCharacter(font, text[i]);
    }
    glEnd();
}  